#include "Link.h"
#include "CommonFunction.h"
#include "UnitManager.h"
//---------------------------------------------------------------
// Link
//---------------------------------------------------------------
int Link::LoadFromString(const char *string_data)
{
	int len_sum = 0;
	int len = __super::LoadFromString(string_data);
	len_sum += len;

	char buf[BUFFER_LEN];
	int ret = 0;

	ret = GetOneString(string_data + len_sum, buf, &len);
	assert(ret >= 0 && len > 0);
	this->description_unit = atoi(buf);
	len_sum += len + 1;

	ret = GetOneString(string_data + len_sum, buf, &len);
	assert(ret >= 0 && len > 0);
	this->weight = atoi(buf);
	len_sum += len + 1;

	ret = GetOneString(string_data + len_sum, buf, &len);
	assert(ret >= 0 && len > 0);
	this->owner_unit = atoi(buf);
	len_sum += len + 1;

	ret = GetOneString(string_data + len_sum, buf, &len);
	assert(len > 0);
	this->other_unit = atoi(buf);
	len_sum += len + 1;
	return len_sum;
}

const String &Link::GetDebugString(void) const
{
	return UnitManager::Instance()->GetDebugString(description_unit);
}

String Link::GetDebugDetail(void) const
{
	UnitManager *unit_manager = UnitManager::Instance();
	char buf[BUFFER_LEN];
	sprintf_s(buf, sizeof(buf), "description=%s, weight=%d, owner=%s, other=%s",
		unit_manager->GetDebugString(description_unit).c_str(), weight,
		unit_manager->GetDebugString(owner_unit).c_str(), unit_manager->GetDebugString(other_unit).c_str());
	return __super::GetDebugDetail() + buf;
}